﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows;
using System.ComponentModel;

namespace StoryMaker.Common
{
    public class ShapeDataObject : IDataObject
    {
        public const string ShapeFormat = "ShapeFormat";
        public ShapeDataObject(StoryShape shape)
        {
            _shape = shape;
        }

        private StoryShape _shape;
        public object GetData(string format, bool autoConvert)
        {
            return _shape;
        }

        public object GetData(Type format)
        {
            if (format.IsSubclassOf(typeof(StoryShape)))
            {
                return GetData(ShapeFormat);
            }
            return null;
        }

        public object GetData(string format)
        {
            return GetData(format, true);
        }

        public bool GetDataPresent(string format, bool autoConvert)
        {
            return format == ShapeFormat;
        }

        public bool GetDataPresent(Type format)
        {
            return format != null && format.IsSubclassOf(typeof(StoryShape));
        }

        public bool GetDataPresent(string format)
        {
            return format == ShapeFormat;
        }

        public string[] GetFormats(bool autoConvert)
        {
            return new string[] { ShapeFormat };
        }

        public string[] GetFormats()
        {
            return new string[] { ShapeFormat };
        }

        public void SetData(string format, object data, bool autoConvert)
        {
            _shape = (StoryShape)data;
        }

        public void SetData(Type format, object data)
        {
            _shape = (StoryShape)data;
        }

        public void SetData(string format, object data)
        {
            _shape = (StoryShape)data;
        }

        public void SetData(object data)
        {
            _shape = (StoryShape)data;
        }
    }
    public abstract class StoryShape : NotifyPropertyChangedBase, ICloneable
    {
        public override string ToString()
        {
            return ShapeName;
        }
        public StoryShape(Brush brush, bool fillShape, double height, double width)
        {
            this.Brush = brush;
            this.FillShape = fillShape;
            this.Height = height;
            this.Width = width;
        }

        public StoryShape() : this(Brushes.Green, true, 30, 30) { }

        public string ShapeName
        {
            get { return this.GetType().Name; }
        }

        private double _height;
        public double Height
        {
            get { return _height; }
            set
            {
                if (!EqualityComparer<double>.Default.Equals(_height, value))
                {
                    _height = value;
                    NotifyPropertyChanged("Height");
                }
            }
        }

        private double _width;
        public double Width
        {
            get { return _width; }
            set
            {
                if (!EqualityComparer<double>.Default.Equals(_width, value))
                {
                    _width = value;
                    NotifyPropertyChanged("Width");
                }
            }
        }

        private double _left;
        public double Left
        {
            get { return _left; }
            set
            {
                if (_left != value)
                {
                    _left = value;
                    NotifyPropertyChanged("Left");
                }
            }
        }

        private double _top;
        public double Top
        {
            get { return _top; }
            set
            {
                if (_top != value)
                {
                    _top = value;
                    NotifyPropertyChanged("Top");
                }
            }
        }

        private Brush _brush;
        public Brush Brush
        {
            get { return _brush; }
            set
            {
                if (_brush != value)
                {
                    _brush = value;
                    NotifyPropertyChanged("Brush");
                    NotifyPropertyChanged("StrokeBrush");
                    NotifyPropertyChanged("FillBrush");
                }
            }
        }

        private bool _fillShape;
        public bool FillShape
        {
            get { return _fillShape; }
            set
            {
                if (_fillShape != value)
                {
                    _fillShape = value;
                    NotifyPropertyChanged("FillShape");
                    NotifyPropertyChanged("StrokeBrush");
                    NotifyPropertyChanged("FillBrush");
                }
            }
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }

}
